﻿//新增栏目
InsertNormal_Channel = function (id) {

    Ext.define("ContentTemplateModel", {
        extend: 'Ext.data.Model',
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: '/manager/Normal_TemplateList/List/articlecontent',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },

        fields: ['Id', 'TemplateTitle']
    });

    //模板
    var ContentTemplateDs = Ext.create('Ext.data.Store', {
        autoLoad: true,
        pageSize: 1000,
        model: 'ContentTemplateModel'
    });
    Ext.define("Normal_TemplatesModel", {
        extend: 'Ext.data.Model',
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: '/manager/Normal_TemplateList/List/articlechannel',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },

        fields: ['Id', 'TemplateTitle']
    });

    //模板
    var TemplatesDs = Ext.create('Ext.data.Store', {
        autoLoad: true,
        pageSize: 1000,
        model: 'Normal_TemplatesModel'
    });

    Ext.define("Normal_ThumbnailModel", {
        extend: 'Ext.data.Model',
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: '/manager/Normal_Thumbnail/List/m',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        },

        fields: ['Id', 'Title']
    });

    //缩略图
    var ThumbnailDs = Ext.create('Ext.data.Store', {
        autoLoad: true,
        pageSize: 1000,
        model: 'Normal_ThumbnailModel'
    });
    var InsertNormal_ChannelForm = Ext.create("Ext.form.Panel", {
        width: 400,
        height: 450,

        autoScroll: true,
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 30,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [
        {
            xtype: 'tabpanel',
            plain: true,
            activeTab: 0,
            height: 400,
            items: [{
                title: '基本信息',
                defaults: { bodyStyle: 'padding:10px', labelAlign: 'right', anchor: '90%', msgTarget: "side" },
                defaultType: 'textfield',
                items: [{
                    name: "ReId",
                    fieldLabel: "<font color='red'>*</font>所属栏目Id",
                    allowBlank: false,
                    blankText: "所属栏目Id不能为空",
                    readOnly: true,
                    value: id,
                    regex: /^[\d]{0,10}$/,
                    regexText: "请填写0～10个数字"
                }, {
                    name: "Title",
                    fieldLabel: "<font color='red'>*</font>栏目名称",
                    allowBlank: false,
                    blankText: "栏目名称不能为空",
                    regex: /^[\S]{1,20}$/,
                    regexText: "请填写1～20个字符"
                }, {
                    name: "SEOTitle",
                    fieldLabel: "SEO栏目名称",
                    width: 300,
                    regex: /^[\S]{0,60}$/,
                    regexText: "请填写0～60个字符"
                }, {
                    name: "KeyWords",
                    fieldLabel: "关键词",
                    regex: /^[\S]{0,50}$/,
                    regexText: "请填写0～50个字符"
                }, {
                    name: "Info",
                    xtype: "textareafield",
                    fieldLabel: "<font color='red'>*</font>栏目简介",
                    allowBlank: false,
                    blankText: "栏目简介不能为空",
                    regex: /^[\S]{1,200}$/,
                    regexText: "请填写1～200个字符"
                }, {
                    name: "Dir",
                    fieldLabel: "栏目目录"
                }, {
                    name: "OrderNum",
                    fieldLabel: "<font color='red'>*</font>排序数",
                    allowBlank: false,
                    value: 101,
                    blankText: "排序数不能为空",
                    regex: /^[\d]{0,10}$/,
                    regexText: "请填写0～10个数字"
                }, {
                    name: "ChannelType",
                    fieldLabel: "<font color='red'>*</font>默认模型",
                    xtype: "combo",
                    //传入后台真实值value field /value
                    editable: false,
                    anchor: '90%',
                    value: "Article",
                    store: Ext.create('Ext.data.Store', {
                        fields: ['show', 'value'],
                        data: [
			                        { "show": "文章", "value": "Article" },
			                        { "show": "图片", "value": "Photo" },
			                        { "show": "下载", "value": "Soft" },
			                        { "show": "视频", "value": "Video" }
			                ]
                    }),
                    queryMode: 'local',
                    displayField: 'show',
                    valueField: 'value',
                    listeners: {
                        'change': function (node, newValue, oldValue, eOpts) {
                            TemplatesDs.proxy.url = "/manager/Normal_TemplateList/List/" + newValue + "channel";
                            TemplatesDs.load();

                            ContentTemplateDs.proxy.url = "/manager/Normal_TemplateList/List/" + newValue + "content";
                            ContentTemplateDs.load();
                        }
                    }
                }, {

                    name: "Enabled",
                    fieldLabel: "是否启用",
                    xtype: "combo",
                    //传入后台真实值value field /value
                    editable: false,
                    anchor: '90%',
                    value: true,
                    store: Ext.create('Ext.data.Store', {
                        fields: ['show', 'value'],
                        data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                    }),
                    queryMode: 'local',
                    displayField: 'show',
                    valueField: 'value'
                }, {
                    name: "IsNav",
                    fieldLabel: "是否导航显示",
                    xtype: "combo",
                    //传入后台真实值value field /value
                    editable: false,
                    anchor: '90%',
                    value: true,
                    store: Ext.create('Ext.data.Store', {
                        fields: ['show', 'value'],
                        data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                    }),
                    queryMode: 'local',
                    displayField: 'show',
                    valueField: 'value'


                }, {
                    name: "IsHtml",
                    fieldLabel: "是否静态",
                    xtype: "combo",
                    //传入后台真实值value field /value
                    editable: false,
                    anchor: '90%',
                    value: false,
                    store: Ext.create('Ext.data.Store', {
                        fields: ['show', 'value'],
                        data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                    }),
                    queryMode: 'local',
                    displayField: 'show',
                    valueField: 'value'
                }, {
                    name: "IsPart",
                    fieldLabel: "栏目属性",
                    xtype: "combo",
                    //传入后台真实值value field /value
                    editable: false,
                    anchor: '90%',
                    value: 1,
                    store: Ext.create('Ext.data.Store', {
                        fields: ['show', 'value'],
                        data: [
			                        { "show": "频道封面(不能添加文档)", "value": 0 },
			                        { "show": "最终列表(可以发布文档)", "value": 1 },
			                        { "show": "外部链接(栏目目录处填写网址)", "value": 2 },
                                    { "show": "站群链接(栏目目录处填写网址)", "value": 3 }
			                    ]
                    }),
                    queryMode: 'local',
                    displayField: 'show',
                    valueField: 'value'
                }
                    ]



            }, {
                title: '高级选项',
                defaults: { bodyStyle: 'padding:10px', labelAlign: 'right', anchor: '90%', msgTarget: "side" },
                defaultType: 'textfield',

                items: [
                   {
                       name: "TemplateId",
                       fieldLabel: "<font color='red'>*</font>栏目模板",
                       allowBlank: false,
                       xtype: "combo",
                       //传入后台真实值value field /value
                       anchor: '90%',
                       store: TemplatesDs,
                       value: 0,
                       displayField: 'TemplateTitle',
                       queryMode: 'local',
                       valueField: 'Id',
                       listeners: {
                           afterRender: function (combo) {
                               combo.setValue(0);
                           }
                       }
                   },{
                       name: "ContentTemplateId",
                       fieldLabel: "<font color='red'>*</font>内容模板",
                       allowBlank: false,
                       xtype: "combo",
                       //传入后台真实值value field /value
                       anchor: '90%',
                       store: ContentTemplateDs,
                       value: 0,
                       displayField: 'TemplateTitle',
                       queryMode: 'local',
                       valueField: 'Id',
                       listeners: {
                           afterRender: function (combo) {
                               combo.setValue(0);
                           }
                       }
                   }, {
                       name: "Target",
                       fieldLabel: "<font color='red'>*</font>打开方式",
                       xtype: "combo",
                       //传入后台真实值value field /value
                       editable: false,
                       anchor: '90%',
                       value: "blank",
                       store: Ext.create('Ext.data.Store', {
                           fields: ['show', 'value'],
                           data: [
			                    { "show": "新窗口", "value": "blank" },
			                    { "show": "本页面", "value": "self" }
			                ]
                       }),
                       queryMode: 'local',
                       displayField: 'show',
                       valueField: 'value'
                   }, {
                       name: "ReadGroup",
                       fieldLabel: "阅读权限",
                       regex: /^[\d]{1,10}$/,
                       regexText: "请填写1～10个数字"
                   }, {
                       name: "SiteSeoBottom",
                       xtype: "textareafield",
                       fieldLabel: "群站底部Seo关键词"
                   }, {
                       name: "SiteImg",
                       xtype: "textareafield",
                       fieldLabel: "站群图片"
                   }, {
                       name: "DefaultThumbs",
                       fieldLabel: "<font color='red'>*</font>默认缩略图尺寸",
                       allowBlank: false,
                       xtype: "combo",
                       //传入后台真实值value field /value
                       anchor: '90%',
                       value: 0,
                       store: ThumbnailDs,
                       autoRender: false,
                       displayField: 'Title',
                       queryMode: 'local',
                       valueField: 'Id',
                       listeners: {
                           afterRender: function (combo) {
                               combo.setValue(0);
                           }
                       }
                   }, {
                       name: "IsPost",
                       fieldLabel: "允许发布",
                       xtype: "combo",
                       //传入后台真实值value field /value
                       editable: false,
                       anchor: '90%',
                       value: true,
                       store: Ext.create('Ext.data.Store', {
                           fields: ['show', 'value'],
                           data: [
			                    { "show": "是", "value": true },
			                    { "show": "否", "value": false }
			                ]
                       }),
                       queryMode: 'local',
                       displayField: 'show',
                       valueField: 'value'

                   }
                    ]
            }, {
                title: '栏目内容',
                defaults: { bodyStyle: 'padding:10px', labelAlign: 'right', msgTarget: "side" },
                labelWidth: 30,
                defaultType: 'textfield',
                items: [{
                    name: "HtmlInfo",
                    xtype: "textareafield",
                    fieldLabel: "栏目简介",
                    width: 300,
                    height: 360
                }]
            }]
        }
        ]
    });


    var InsertNormal_ChannelWin = Ext.create('Ext.window.Window', {
        title: "新增栏目",
        width: 400,
        height: 480,

        layout: "fit",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        collapsible: true, //允许缩放条
        closeAction: 'destroy',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [InsertNormal_ChannelForm],

        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function () {
                //alert(InsertNormal_ChannelForm.getForm().isValid())
                if (InsertNormal_ChannelForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function () { }, 1000);
                    InsertNormal_ChannelForm.form.submit({
                        url: "/manager/Normal_Channel/Insert/",
                        method: "POST",
                        success: function (form, action) {
                            //成功后
                            Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Normal_ChannelStore.loadPage(1);
                                Normal_ChannelTreeStore.load();
                                Ext.MessageBox.hide();
                                Ext.helper.msg("恭喜", "新增成功!");
                                InsertNormal_ChannelWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("新增失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "新增失败!");
                                    InsertNormal_ChannelWin.hide();
                                }

                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "新增失败!");
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function () {
                //加载表单数据
                InsertNormal_ChannelForm.getForm().reset();
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function () {
                InsertNormal_ChannelWin.hide();
            }
        }]

    });
    console.log(ThumbnailDs)
    InsertNormal_ChannelWin.show();
}
